package dao;

import java.util.List;

import modelo.Telefone;

import org.hibernate.Criteria;
import org.hibernate.Session;

public class TelefoneDAO {
	public static final long UNSAVED_ID = 0;
	

	
	public TelefoneDAO() throws Exception{
	}
	

	public static void persiste(Telefone telefone, Session session) throws Exception{
		if(telefone.getId()==UNSAVED_ID)
			adiciona(telefone, session);
		else
			atualiza(telefone, session);
	}
	
	public static void adiciona(Telefone telefone, Session session) throws Exception{
		session.save(telefone);
	}

	public static void remove(Telefone telefone, Session session) throws Exception{
		session.delete(telefone);
	}

	public static void atualiza(Telefone telefone, Session session) throws Exception{
		session.update(telefone);
	}

	public static Telefone obtem(long id, Session session) throws Exception{
		return (Telefone) session.load(Telefone.class, id);
	}
	
	public static List<Telefone> listar(String filtro, Session session) throws Exception{
		Criteria crit = session.createCriteria(Telefone.class);
//		crit.add(Restrictions.like("nome", "M", MatchMode.EXACT));
//		crit.addOrder(Order.desc("nome"));
		return crit.list();
		
	}

}
